package examples.vista;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToolBar;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;

import examples.controller.TextEditorController_useless;

public class TextEditorView_useless extends JFrame {

	private static final long serialVersionUID = 1L;

	private RSyntaxTextArea textArea;
	private JTextField searchField;
	private JCheckBox regexCB;
	private JCheckBox matchCaseCB;

	private TextEditorController_useless mController;
	
	public TextEditorView_useless(TextEditorController_useless controller) {
		JPanel cp = new JPanel(new BorderLayout());
		mController = controller;
		mController.setmTEW(this);
		
		setTextArea(new RSyntaxTextArea(20, 60));
		getTextArea().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
		getTextArea().setCodeFoldingEnabled(true);
		getTextArea().setAntiAliasingEnabled(true);
		RTextScrollPane sp = new RTextScrollPane(getTextArea());
		sp.setFoldIndicatorEnabled(true);
		cp.add(sp);
		// Create a toolbar with searching options.
		JToolBar toolBar = new JToolBar();
		searchField = new JTextField(30);
		toolBar.add(searchField);
		final JButton nextButton = new JButton("Find Next");
		nextButton.setActionCommand("FindNext");
		nextButton.addActionListener(mController);
		toolBar.add(nextButton);
		searchField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				nextButton.doClick(0);
			}
		});
		JButton prevButton = new JButton("Find Previous");
		prevButton.setActionCommand("FindPrev");
		prevButton.addActionListener(mController);
		toolBar.add(prevButton);
		regexCB = new JCheckBox("Regex");
		toolBar.add(regexCB);
		matchCaseCB = new JCheckBox("Match Case");
		toolBar.add(matchCaseCB);
		cp.add(toolBar, BorderLayout.NORTH);
		
		final JButton saveButton = new JButton("Save");
		saveButton.setActionCommand("Save");
		saveButton.addActionListener(mController);
		toolBar.add(nextButton);

		setContentPane(cp);
		setTitle("aiXML Text editor");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		pack();
		setLocationRelativeTo(null);
	}

	public void notFound(){
		JOptionPane.showMessageDialog(this, "Text not found");
	}
	public RSyntaxTextArea getTextArea() {
		return textArea;
	}

	public void setTextArea(RSyntaxTextArea textArea) {
		this.textArea = textArea;
	}

	public JTextField getSearchField() {
		return searchField;
	}

	public JCheckBox getRegexCB() {
		return regexCB;
	}

	public JCheckBox getMatchCaseCB() {
		return matchCaseCB;
	}

	// Not Necessary 
//	public void setController(TextEditorController controller) {
//		this.mController = controller;
//	}
}